package com.xiaoyao.demo.controller;

import com.xiaoyao.demo.service.IDemoService;
import com.xiaoyao.mvcframework.annotation.YXAutowired;
import com.xiaoyao.mvcframework.annotation.YXController;
import com.xiaoyao.mvcframework.annotation.YXRequestMapping;
import com.xiaoyao.mvcframework.annotation.YXRequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@YXController
@YXRequestMapping("/demo")
public class DemoController {

    @YXAutowired
    private IDemoService demoService;

    @YXRequestMapping("getName")
    public void getName(HttpServletRequest req, HttpServletResponse resp, @YXRequestParam("name") String name){
        String result = demoService.getName(name);
        try {
            resp.getWriter().write(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @YXRequestMapping("getName2")
    public void getName2(HttpServletRequest req, HttpServletResponse resp){
        String result = demoService.getName(String.valueOf("test2"));
        try {
            resp.getWriter().write(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
